﻿using System.Drawing;

namespace Sidvall.Office
{
	public class WorksheetShapeCollection : IWorksheetShapeCollection
	{
		#region Public Members

		#region Count

		public int Count
		{
			get
			{
				return this.Worksheet.InternalWorksheet.Shapes.Count;
			}
		}

		#endregion
		#region this

		public IWorksheetShape this[int index]
		{
			get
			{
				var item = this.Worksheet.InternalWorksheet.Shapes[index];
				return new WorksheetShape(item);
			}
		}

		#endregion

		#region AddImage

		public WorksheetShape AddImage(object image)
		{
			var imageShape = new Infragistics.Documents.Excel.WorksheetImage(image as Image);
			imageShape.TopLeftCornerCell = this.Worksheet.InternalWorksheet.Rows[0].Cells[0];
			imageShape.BottomRightCornerCell = this.Worksheet.InternalWorksheet.Rows[1].Cells[1];
			this.Worksheet.InternalWorksheet.Shapes.Add(imageShape);
			return new WorksheetShape(imageShape);
		}

		#endregion
		#region Clear

		public void Clear()
		{
			this.Worksheet.InternalWorksheet.Shapes.Clear();
		}

		#endregion
		#region RemoveAt

		public void RemoveAt(int index)
		{
			this.Worksheet.InternalWorksheet.Shapes.RemoveAt(index);
		}

		#endregion
		#region ToString

		public override string ToString()
		{
			return "WorksheetShapeCollection - Sidvall.Office.IG";
		}

		#endregion

		#region IWorksheetShapeCollection Members

		IWorksheetShape IWorksheetShapeCollection.AddImage(object image)
		{
			return AddImage(image);
		}
		System.Collections.Generic.IEnumerator<IWorksheetShape> System.Collections.Generic.IEnumerable<IWorksheetShape>.GetEnumerator()
		{
			foreach (var item in this.Worksheet.InternalWorksheet.Shapes)
				yield return new WorksheetShape(item);
		}
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			foreach (var item in this.Worksheet.InternalWorksheet.Shapes)
				yield return new WorksheetShape(item);
		}

		#endregion

		#endregion
		#region Private Members

		internal Worksheet Worksheet { get; set; }

		#endregion
		#region Constructors

		public WorksheetShapeCollection(Worksheet worksheet)
		{
			if (worksheet == null)
				throw new System.ArgumentNullException("worksheet");
			this.Worksheet = worksheet;
		}

		#endregion
	}
}
